﻿using Newtonsoft.Json;
using shuatibao.Tool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace shuatibao.Web.Account
{
    /// <summary>
    /// UserInfo 获取小程序的用户信息
    /// </summary>
    public class UserInfo : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            // 获取POST请求的JSON数据
            string requestJson = new StreamReader(context.Request.InputStream).ReadToEnd();

            Dictionary<string, string> parameters = JsonConvert.DeserializeObject<Dictionary<string, string>>(requestJson);
           
            string openId = parameters["openId"].ToString();
            string unionId = parameters["unionId"].ToString();

            WechatUserModel userModel = AccountAction.createUserManagerMain(unionId, openId, "" );
            WechatUserDataModel userDataModel = new WechatUserDataModel();
            userDataModel.code = "200";
            userDataModel.data = userModel;
            userDataModel.msg = "";
            Utils.jsonBackManager(context,Utils.toJSON(userDataModel));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}